home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 51 / Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso / -serious- / programming / e / powerd / source / examples / ferguson.d < prev    next >
Text File  |  2000-01-27  |  1KB  |  60 lines

  1. // Ferguson.d - example of how to generate ferguson's kubics (curves) in D
  2.  
  3. MODULE    'intuition/intuition',
  4.             'utility/tagitem',
  5.             'startup/startup_ieee'
  6.  
  7. PROC main()
  8.     DEF w:PTR TO Window
  9.     IF w:=OpenWindowTags(NIL,
  10.             WA_InnerWidth,320,
  11.             WA_InnerHeight,320,
  12.             WA_IDCMP,IDCMP_CLOSEWINDOW,
  13.             WA_Flags,WFLG_DRAGBAR|WFLG_GIMMEZEROZERO|WFLG_RMBTRAP|WFLG_ACTIVATE|WFLG_CLOSEGADGET|WFLG_DEPTHGADGET,
  14.             WA_Title,'Ferguson''s Cubic',
  15.             TAG_END)
  16.     
  17.         Ferguson(w.RPort,
  18.           -5.0,  0.0,  // A
  19.          -10.0, 10.0,  // a
  20.            5.0,  0.0,  // B
  21.          -10.0,-10.0,  // b
  22.           1000)
  23.     
  24.         WaitPort(w.UserPort)
  25.         CloseWindow(w)
  26.     ENDIF
  27. ENDPROC
  28.  
  29. /*
  30.     rp            - window rastport
  31.     xA,yA        - coordinates of point A
  32.     xa,ya        - vector in point A
  33.     xB,yB        - coordinates of point B
  34.     xb,yb        - vector in point B
  35.     steps        - number of elementar lines
  36. */
  37. PROC Ferguson(rp,xA:FLOAT,yA:FLOAT,xa:FLOAT,ya:FLOAT,xB:FLOAT,yB:FLOAT,xb:FLOAT,yb:FLOAT,steps)
  38.     DEFF    delta,t,x,y,f0,f1,f2,f3
  39.     DEF    i
  40.     delta:=1.0/steps
  41.     SetAPen(rp,1)
  42.     x:=xA*20.0
  43.     y:=yA*-20.0
  44.     Move(rp,x+160,y+160)
  45.     FOR i:=0 TO steps
  46.         t:=delta*i
  47.         f0:=2.0*t*t*t-3.0*t*t+1.0        // Ferguson's polynoms
  48.         f1:=-2.0*t*t*t+3.0*t*t
  49.         f2:=t*t*t-2.0*t*t+t
  50.         f3:=t*t*t-t*t
  51.         x:=xA*f0+xB*f1+xa*f2+xb*f3        // parametrical representations for x and y coords
  52.         y:=yA*f0+yB*f1+ya*f2+yb*f3
  53.         x*=20.0
  54.         y*=-20.0
  55.         Draw(rp,x+160,y+160)
  56.     ENDFOR
  57. ENDPROC
  58.  
  59. // MarK 7/8/99
  60.